package com.immoc.demo.controller;

import com.immoc.demo.entity.Area;
import com.immoc.demo.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author zzy
 * @Description TODO
 * @Date 2018/4/7 17:06
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/superadmin")
public class AreaController {
    @Autowired
    private AreaService areaService;
    @RequestMapping(value = "listarea",method = RequestMethod.GET)
    public Map<String,Object> listArea(){
        Map<String,Object> modelMap = new HashMap<>();
        List<Area> areaList = areaService.getAreaList();
        modelMap.put("arealist",areaList);
        return modelMap;
    }

    @RequestMapping(value = "getareabyid",method = RequestMethod.GET)
    public Map<String,Object> getAreaById(Integer id){
        Map<String,Object> modelMap = new HashMap<>();
        Area area = areaService.getAreaById(id);
        modelMap.put("area",area);
        return modelMap;
    }

    @RequestMapping(value = "addarea",method = RequestMethod.POST)
    public  Map<String,Object> addArea(@RequestBody Area area){
        Map<String,Object> modelMap = new HashMap<>();
        //todo
        modelMap.put("success",areaService.addArea(area));
        return modelMap;
    }

    /**
     * 接受复杂参数时，需要使用RequestBody标签，基本类型则不需要
     */
    @RequestMapping(value = "modifyarea",method = RequestMethod.POST)
    public  Map<String,Object> modifyArea(@RequestBody Area area){
        Map<String,Object> modelMap = new HashMap<>();
        //todo
        modelMap.put("success",areaService.modifyArea(area));
        return modelMap;
    }
    @RequestMapping(value = "removearea",method = RequestMethod.POST)
    public  Map<String,Object> removeArea( Integer areaid){
        Map<String,Object> modelMap = new HashMap<>();
        //todo
        modelMap.put("success",areaService.deleteByAreaId(areaid));
        return modelMap;
    }

}
